package com.myres.model;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class Product extends BasicObject{
	public static final long serialVersionUID = 543435431434l;
	private int cid;
	public int getCid() {
		return cid;
	}

	public void setCid(int cid) {
		this.cid = cid;
	}

	private int sid;// seems useless
	private int shopId;
	private Shop shop;
	private Series series;
	private float price;
	private int stock;
	private String icon;
	private String description;
	private int score;
	private byte onIndex;
	private byte onRecommend;
	private byte onPromotion;
	private int state;
	private int smsCode;
	private String name;
	private Timestamp addTime;
	public Timestamp getAddTime() {
		return addTime;
	}

	public void setAddTime(Timestamp addTime) {
		this.addTime = addTime;
	}

	private Set<Critic> critics;
	private int priority;
	private String summary;

	public String getSummary() {
		return summary;
	}

	public int getPriority() {
		return priority;
	}

	public Shop getShop() {
		return shop;
	}

	public void setShop(Shop shop) {
		this.shop = shop;
	}
     
	public int getShopId() {
	      return this.shopId;
	}
	
	public void setShopId(int shopId) {
	    this.shopId = shopId;
	}
	
	public Series getSeries() {
		return series;
	}

	public void setSeries(Series series) {
		this.series = series;
		if(series != null)this.sid=series.getId();
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Set<Critic> getCritics() {
		return critics;
	}

	public void setCritics(Set<Critic> critics) {
		this.critics = critics;
	}

	public int getSmsCode() {
		return smsCode;
	}

	public void setSmsCode(int smsCode) {
		this.smsCode = smsCode;
	}

	public int getState() {
		return state;
	}

	public void setState(int state) {
		this.state = state;
	}

	public int getSid() {
		return sid;
	}

	public void setSid(int sid) {
		if(series == null ) {
			series = new Series();
			series.setId(sid);
		}
		this.sid = sid;
	}

	public float getPrice() {
		return price;
	}

	public void setPrice(float price) {
		this.price = price;
	}

	public int getStock() {
		return stock;
	}

	public void setStock(int stock) {
		this.stock = stock;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public int getScore() {
		return score;
	}

	public void setScore(int score) {
		this.score = score;
	}

	public byte getOnIndex() {
		return onIndex;
	}

	public void setOnIndex(byte onIndex) {
		this.onIndex = onIndex;
	}

	public byte getOnRecommend() {
		return onRecommend;
	}

	public void setOnRecommend(byte onRecommend) {
		this.onRecommend = onRecommend;
	}

	public byte getOnPromotion() {
		return onPromotion;
	}

	public void setOnPromotion(byte onPromotion) {
		this.onPromotion = onPromotion;
	}

	public static synchronized List<Product> populate(ResultSet rs)
			throws SQLException {
		List<Product> l = new ArrayList<Product>();
		while (rs.next()) {
			Product c = new Product();
			c.setId(rs.getInt(1));
			c.setNO(rs.getString(2));
			c.setSid(rs.getInt(3));
			c.setName(rs.getString(4));
			c.setPrice(rs.getFloat(5));
			c.setStock(rs.getInt(6));
			c.setIcon(rs.getString(7));
			c.setDescription(rs.getString(8));
			c.setScore(rs.getInt(9));
			c.setOnIndex(rs.getByte(10));
			c.setOnPromotion(rs.getByte(11));
			c.setOnRecommend(rs.getByte(12));
			c.setState(rs.getInt(13));
			c.setSmsCode(rs.getInt(14));
			l.add(c);
		}
		return l;
	}

	public void setPriority(int i) {
		// TODO Auto-generated method stub
		this.priority =i;
	}

	public void setSummary(String string) {
		// TODO Auto-generated method stub
		this.summary =string;
	}
}
